package com.longqinuo.mycarservice.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;


import com.longqinuo.mycarservice.R;

import java.util.List;

/**
 * 自定义快递电话列表适配器
 * Created by zxw on 2016/6/8.
 */
public class PostImageAdapter extends BaseAdapter {
    private Context context;
    private List<String> mList;
    private Bitmap bitmap;
    public PostImageAdapter(Context context, List<String> list) {
        // TODO Auto-generated constructor stub
        this.context = context;
        this.mList = list;
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return mList.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return mList.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.publish_add_image_item, null);
            holder = new ViewHolder(convertView);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String path = mList.get(position);
        bitmap = BitmapFactory.decodeFile(path);
        holder.show.setImageBitmap(bitmap);
        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mList.remove(position);
                notifyDataSetChanged();
            }
        });

        return convertView;
    }

    public class ViewHolder{

        public ViewHolder(View itemView) {
            this.show = (ImageView) itemView.findViewById(R.id.iv_show_image_post);
            this.delete = (ImageView) itemView.findViewById(R.id.iv_delete_image_post);
        }

        private ImageView show;
        private ImageView delete;
    }
}
